import 'package:flutter/material.dart';
import '../utils/g.dart';

enum AuthStatus {
  checking, 
  authenticated, 
  notAuthenticate
}

class AuthProvider extends ChangeNotifier {
  String? _token;
  AuthStatus authStatus = AuthStatus.checking;

  AuthProvider() {
    this.isAuthenticated();
  }

  login(String email, String password) {
    this._token = 'sdfuoiho13iounf934';
    G.prefs().setString('token', this._token!);
    authStatus = AuthStatus.authenticated;

    notifyListeners();
  }

  Future<bool> isAuthenticated() async {
    final token = G.prefs().getString('token');
    if (token == null) {
      authStatus = AuthStatus.notAuthenticate;

      notifyListeners();
      return false;
    }

    await Future.delayed(Duration(milliseconds: 1000));
    authStatus = AuthStatus.authenticated;
    
    notifyListeners();
    return true;
  }
}
